package com.ruoyi.gams.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.gams.service.IGamsHomePageService;
import com.ruoyi.gams.vo.HomePageVO;
import com.ruoyi.gams.vo.param.WindowQueueCountParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据中心
 */
@Api(tags = "数据中心")
@RestController
@RequestMapping("/gams/dataCenter")
public class GamsDataCenterController extends BaseController
{

    @Autowired
    private IGamsHomePageService homePageService;

    /**
     * 窗口数据统计
     *
     * @param type  1.排队时长 2.办理时长 3.办理数量
     * @param order 1.前几名 0.后几名
     * @param limit 数量 5 条
     * @return
     */
    @ApiOperation("窗口排队时长统计")
    @ResponseBody
    @GetMapping("/windowQueueCount")
    public AjaxResult windowQueueTimeCount(WindowQueueCountParam param)
    {
        List<JSONObject> list = new ArrayList<>();
        if (param.getOrder() == 1)
        {
            for (int i = 0; i < param.getLimit(); i++)
            {
                JSONObject result = new JSONObject();
                result.put("name", "窗口" + i);
                result.put("count", i);
                list.add(result);
            }
        }
        else
        {
            for (int i = param.getLimit(); i > 0; i--)
            {
                JSONObject result = new JSONObject();
                result.put("name", "窗口" + i);
                result.put("count", i);
                list.add(result);
            }
        }
        return AjaxResult.success(list);
    }

    @ApiOperation("排队信息统计")
    @ResponseBody
    @GetMapping("/queueCount")
    public AjaxResult queueCount()
    {
        JSONObject vo = homePageService.queueCount();
        return AjaxResult.success(vo);
    }

}
